package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.entity.SetmealDish;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface SetMealMapper {
    Page<Setmeal> getPage(SetmealPageQueryDTO queryDTO);

    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into setmeal (category_id, name, price, status, description, image) values (#{categoryId}, #{name}, #{price}, #{status}, #{description}, #{image})")
    void insertSetmeal(Setmeal setmeal);

    void insertSetmealDishs(Long setmealId, List<SetmealDish> setmealDishes);

    void updateSetmeal(Setmeal setmeal);

    void deleteSetmealDishs(long[] ids);

    void deleteSetmeals(long[] ids);

    @Select("select * from setmeal where id = #{id}")
    Setmeal getSetmealById(Long id);

    @Select("select * from setmeal_dish where setmeal_id = #{setmealId}")
    List<SetmealDish> getSetmealDishsBySetmealId(Long setmealId);

    @Select("select sd.name,sd.copies,d.image,d.description from  setmeal_dish sd  left join dish d on sd.dish_id = d.id  where sd.setmeal_id = #{setmealId}")
    List<DishItemVO> getDishItemBySetmealId(Long setmealId);

    @Select("select * from setmeal where category_id = #{categoryId}")
    List<SetmealVO> getSetmealsByCategoryId(Long categoryId);
}
